import { Body, Controller, Get, Post, Query, Req } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { WordCollectionService } from './word-collection.service';
import { WordCollection } from './word-collection.entity';
import { ApiRes, ApiResType } from 'src/common/decorator/api-res.decorator';
import { WordCollectionListDto } from './dto/list.dto';
import { AddWordCollectionDto } from './dto/add.dto';
import { RemoveWordCollectionDto } from './dto/remove.dto';

@ApiTags('app单词收藏模块')
@ApiBearerAuth()
@Controller('app/wordCollection')
export class WordCollectionController {
  constructor(
    private readonly appWordCollectionService: WordCollectionService,
  ) {}

  @ApiOperation({
    summary: '分页查询已收藏的单词列表',
  })
  @Post('/list')
  @ApiRes(WordCollection, ApiResType.PAGE_ARRAY)
  async list(@Body() data: WordCollectionListDto, @Req() request) {
    const { uid } = request.auth;
    return {
      data: await this.appWordCollectionService.findAll(uid, data),
    };
  }

  @ApiOperation({
    summary: '收藏单词',
  })
  @Post('/add')
  async add(@Body() collection: AddWordCollectionDto, @Req() request) {
    const { uid } = request.auth;
    return {
      data: await this.appWordCollectionService.create(uid, collection),
    };
  }

  @ApiOperation({
    summary: '取消收藏',
  })
  @Get('/remove')
  async remove(@Query() data: RemoveWordCollectionDto) {
    return {
      data: await this.appWordCollectionService.remove(data.ids),
    };
  }
}
